<?
Class CountryModule{
    var $_connect;
    var $error;
    function CountryModule() {
        $this->_connect = new Dataconnection();
    }
    function getCountry($id){
        $id=  str_replace(" ", "", $id);
        $SQLCommand="
        SELECT
            _country.*
        FROM
            _country
        WHERE
            _country.`delete` is null 
            AND (`id`='$id'
            OR `tag`='$id')
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    function getCountryList($p,$n){
        $srt=($p-1)*$n;
        $SQLCommand="
        SELECT
            *
        FROM
            _country
        WHERE
            
            `delete` is null
        ORDER BY `insert` DESC
        LIMIT $srt,$n
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function getCountry_NumRow(){
        
        $SQLCommand="
        SELECT count(*) as numrow 
        FROM
            _country
        WHERE
            `delete` is null
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        if($data!=null ){
            $row=$data->fetch_array();
            return $row["numrow"];
        }
        return 0;
    }
    function insertCountry($name,$brief,$flag,$map, $background, $geography,$demographics, $government, $economy, $communications,$transportation,$des){
        $SQLCommand="
        INSERT 
            `_country`(
                        `name`,`brief`,`flag`,`map`,`background`,`geography`,`demographics`,`government`,`economy`,`communications`,`transportation`,`des`,`insert`
            )
            VALUE(
                        '$name','$brief','$flag','$map','$background','$geography','$demographics','$government','$economy','$communications','$transportation','$des',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function updateCountry($id,$name,$brief,$flag,$map, $background, $geography,$demographics, $government, $economy, $communications,$transportation,$des){
        $SQLCommand="
        UPDATE 
            `_country`
        SET `name`='$name',
            `brief`='$brief',
            `flag`='$flag',
            `map`='$map',
            `background`='$background',
            `geography`='$geography',
            `demographics`='$demographics',
            `government`='$government',
            `economy`='$economy',
            `communications`='$communications',
            `transportation`='$transportation',
            `des`='$des',
            `update`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function deleteCountry($id){
        $SQLCommand="
        UPDATE 
            `_country`
        SET `delete`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>